package com.mg.flightplan.control;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.DigitsKeyListener;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;

import com.mg.flightplan.R;

public class MainActivity extends Activity {

	public static String CRUISE_SPEED = "CRUISE_SPEED";
	public static String USE_DB = "USE_DB";
    String cruiseSpeed;
    MainActivity instance=null;
    Intent intent;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        instance = this;

    }
    
    /** Called when the user clicks the Send button */
    public void startFP(View view) {

    	intent = new Intent(instance, FplanActivity.class);

    	// Get value from radio buttons
    	boolean dbChecked = ((RadioButton) findViewById(R.id.radio0)).isChecked();
    	if (dbChecked)
    		intent.putExtra(USE_DB,true);
    	else
    		intent.putExtra(USE_DB,false);
    	
    	
    	// prepare the alert box
        Builder alertbox = new Builder(this);
        // set the message to display
        alertbox.setMessage(getString(R.string.askCruiseSpeed));
        // Set an EditText view to get user input 
        
        final EditText input = new EditText(this);
        input.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
        input.setText("120");
        alertbox.setView(input);

		alertbox.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
				String cruiseSpeed = input.getText().toString();
				// Do something with value!
		    	intent.putExtra(CRUISE_SPEED,cruiseSpeed);
		    	startActivity(intent);
			}
		});
		alertbox.show();
		
    }
    public void openFList(View view) {

    	intent = new Intent(instance, FListActivity.class);
    	startActivity(intent);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
 
}
